class ApplicationController < ActionController::Base
  include ApplicationHelper
  before_filter :set_hostname, :set_locale
  protect_from_forgery
  def set_hostname
    @hostname  = "#{request.host_with_port}"
  end
  
  def set_locale
    locale = "vi"
    nguoi_dung = nguoi_dung_hien_tai
    if cookies[:ngon_ngu].present?
      locale = cookies[:ngon_ngu]
    elsif nguoi_dung && nguoi_dung.ngon_ngu.present?
      locale = nguoi_dung.ngon_ngu
    end
    if !['vi', 'en'].include?(locale)
      locale = "vi"
    end
    I18n.locale = locale
  end

  def not_found
    raise ActionController::RoutingError.new('Not Found')
  end
end
